package com.zsy.controller;


import com.zsy.dto.OrderDto;
import com.zsy.pojo.Order;
import com.zsy.pojo.Page;
import com.zsy.pojo.R;
import com.zsy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/order")
public class orderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/submit")
    public R<String> submit(@RequestBody Order order, HttpSession session){
        Long userId = (Long) session.getAttribute("user");

        orderService.submit(order,userId);

        return R.success("下单成功");
    }

    @GetMapping("page")
    public R<Page<Order>> page(Integer page , Integer pageSize ,Long number,String beginTime,String endTime){

       return R.success(orderService.page(page,pageSize,number,beginTime,endTime));
    }

    @GetMapping("userPage")
    public R<Page<OrderDto>> userPage(Integer page, Integer pageSize,HttpSession session){
        Long userId = (Long) session.getAttribute("user");
        return R.success(orderService.pageUser(page,pageSize,userId));

    }




}
